{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "38ebe56d-5a05-484f-9db6-4d9a9ca4b432",
   "metadata": {},
   "source": [
    "Chapter 05\n",
    "\n",
    "# 欧氏距离\n",
    "Book_6《数据有道》 | 鸢尾花书：从加减乘除到机器学习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8fd2e18c-6578-4eb3-a40d-9781282d55fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy.spatial import distance\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "480dd9e7-27fe-44ea-a5d1-b012d23155fd",
   "metadata": {},
   "outputs": [],
   "source": [
    "x_i = (0, 0, 0) # data point\n",
    "q   = (4, 8, 6) # query point"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "41f20fe9-4b51-4d76-8d0b-27390500ee30",
   "metadata": {},
   "outputs": [],
   "source": [
    "# calculate Euclidean distance\n",
    "dst_1 = distance.euclidean(x_i, q)\n",
    "\n",
    "dst_2 = np.linalg.norm(np.array(x_i) - np.array(q))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
